package logic

import (
	"context"
	"videos/model/mysql"

	"videos/videorpc/internal/svc"
	"videos/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectionLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectionLogic {
	return &CollectionLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectionLogic) Collection(in *videorpc.CollectionRequest) (*videorpc.CollectionResponse, error) {
	// todo: add your logic here and delete this line

	collection := mysql.Collection{
		UserId:  int(in.UserId),
		VideoId: int(in.VideoId),
	}

	err := collection.CollectionAdd(mysql.DB)
	if err != nil {
		return nil, err
	}

	return &videorpc.CollectionResponse{
		CollectionId: int64(collection.ID),
	}, nil
}
